package com.winhxd.b2c.customer.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.context.CustomerUser;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.customer.condition.*;
import com.winhxd.b2c.common.domain.customer.model.CustomerUserInfo;
import com.winhxd.b2c.common.domain.customer.vo.*;
import com.winhxd.b2c.common.exception.BusinessException;
import com.winhxd.b2c.common.feign.customer.CustomerServiceClient;
import com.winhxd.b2c.common.util.JsonUtil;
import com.winhxd.b2c.common.util.SecurityCheckUtil;
import com.winhxd.b2c.customer.service.*;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;


@RestController
public class CustomerServiceController implements CustomerServiceClient {


    @Autowired
    private CustomerService customerService;

    @Autowired
    private DistributorService distributorService;

    @Autowired
    private DistributorChannelService distributorChannelService;

    @Autowired
    private CustomerRevenueService customerRevenueService;

    @Autowired
    private CustomerStoreInfoSerivce customerStoreInfoSerivce;

    @Autowired
    private CustomerAddressService customerAddressService;
    private Logger logger = LoggerFactory.getLogger(CustomerServiceController.class);

    /**
     * 查询分销商列表信息
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<PagedList<CustomerDistributorVO>> findDistributerListByCondition(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<PagedList<CustomerDistributorVO>> responseResult = new ResponseResult<PagedList<CustomerDistributorVO>>();
        try {
            PagedList<CustomerDistributorVO> page = distributorService.findDistributerListByCondition(condition);
            responseResult.setData(page);
        } catch (Exception e) {
            logger.error("findDistributerListByCondition查询分销商信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    /**
     * 后台新增一级分销商
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> saveFirstDistributer(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<Boolean>();
            //入参校验
            verfiySaveDistributerParams(condition);
            result.setData(distributorService.saveFirstDistributer(condition));
            return result;
    }

    @Override
    public ResponseResult<CustomerOperationHomePageVO> findOperationHomePage() {
        ResponseResult<CustomerOperationHomePageVO> result = new ResponseResult<CustomerOperationHomePageVO>();
        CustomerOperationHomePageVO vo = customerService.findOperationHomePage();
        result.setData(vo);
        return result;
    }

    /**
     * 分销商渠道类型列表
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<PagedList<CustomerDistributorChannelTypeVO>> findCustomerDistribtorChannelTypeList(@RequestBody DistributorChannelTypeCondition condition) {
        ResponseResult<PagedList<CustomerDistributorChannelTypeVO>> responseResult = new ResponseResult<>();
        try {
            PagedList<CustomerDistributorChannelTypeVO> customerDistribtorChannelTypeList = distributorChannelService.findCustomerDistribtorChannelTypeList(condition);
            responseResult.setData(customerDistribtorChannelTypeList);
        } catch (Exception e) {
            logger.error("findCustomerDistribtorChannelTypeList查询分销商渠道类型失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 后台修改分销商渠道类型状态
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyDistriButorType(@RequestBody DistributorChannelTypeCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        responseResult.setData(distributorChannelService.modifyDistriButorType(condition));
        return responseResult;
    }

    /**
     * 后台新增分销商渠道
     *
     * @param channelCondition
     * @return
     */
    @Override
    public ResponseResult<Boolean> saveDistriButorChannel(@RequestBody DistributorChannelCondition channelCondition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        responseResult.setData(distributorChannelService.saveDistriButorChannel(channelCondition));
        return responseResult;
    }


    /**
     * 一级分销商换绑
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyFirstDistributorBind(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorService.modifyFirstDistributorBind(condition));
        } catch (Exception e) {
            logger.error("modifyFirstDistributorBind：一级分销商换绑失败", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 二级分销商换绑
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifySecondDistributorBind(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorService.modifySecondDistributorBind(condition));
        } catch (Exception e) {
            logger.error("modifySecondDistributorBind：二级分销商换绑失败", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    /**
     * 分销商详情信息查询
     *
     * @param id
     * @return
     */
    @Override
    public ResponseResult<CustomerDetailVO> findDistributerDeatilById(@PathVariable(value = "id") Long id) {
        ResponseResult<CustomerDetailVO> responseResult = new ResponseResult<>();
        try {
            CustomerDetailVO customerDistributorVO = distributorService.findDistributerDeatilById(id);
            responseResult.setData(customerDistributorVO);
        } catch (Exception e) {
            logger.error("findDistributerDeatilById查询分销商详情信息查询失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * zhaoyanbiao
     * 分销商渠道类型级层级详情信息查询
     * @param id
     * @return
     */
    @Override
    public ResponseResult<CustomerDistributorTypeAndChannelVO> getDistributerChannelLevelById(@PathVariable(value = "id") Long id) {
        ResponseResult<CustomerDistributorTypeAndChannelVO> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorChannelService.getDistributerChannelLevelById(id));
        } catch (Exception e) {
            logger.error("getDistributerChannelLevelById分销商渠道类型级层级详情信息查询失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    /**
     * 查询分销商简单信息
     *
     * @param id
     * @return
     */
    @Override
    public ResponseResult<CustomerDistributorSimpleVO> findDistributerSimpleById(@RequestParam(value = "id") Long id) {
        ResponseResult<CustomerDistributorSimpleVO> responseResult = new ResponseResult<>();
        try {
            CustomerDistributorSimpleVO customerDistributorVO = distributorService.findDistributerSimpleById(id);
            responseResult.setData(customerDistributorVO);
        } catch (Exception e) {
            logger.error("findDistributerSimpleById查询分销商详情信息查询失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    /**
     * 修改分销商状态
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyDistributorStatus(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorService.modifyDistributorStatus(condition));
        } catch (Exception e) {
            logger.error("modifyDistributorStatus：修改分销商状态", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    @Override
    public ResponseResult<CustomerAddressVO> selectCustomerAddressById(@RequestParam(value = "id") Long id) {
        ResponseResult<CustomerAddressVO> responseResult = new ResponseResult<CustomerAddressVO>();
        try {
            CustomerAddressVO customerAddress = customerAddressService.selectCustomerAddressById(id);
            responseResult.setData(customerAddress);
        } catch (Exception e) {
            logger.error("selectCustomerAddressById查询地址查询失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    @Override
    public ResponseResult<CustomerUserInfoVO> getCustomerUserInfoById(@RequestParam(value = "customerId") Long customerId) {
        ResponseResult<CustomerUserInfoVO> responseResult = new ResponseResult<>();
        try {
            List<Long> custList = Arrays.asList(customerId);
            List<CustomerUserInfoVO> custInfoList = customerService.findCustomerUserByIds(custList);
            if (!custInfoList.isEmpty()) {
                responseResult.setData(custInfoList.get(0));
            }
        } catch (Exception e) {
            logger.error("getCustomerUserInfoById查询用户信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    @Override
    public ResponseResult<CustomerDistributorTypeAndChannelVO> getCustomerChannelById(@RequestParam(value = "customerId") Long customerId) {
        ResponseResult<CustomerDistributorTypeAndChannelVO> responseResult = new ResponseResult<>();
        try {
            List<Long> custList = Arrays.asList(customerId);
            List<CustomerUserInfoVO> custInfoList = customerService.findCustomerUserByIds(custList);
            if (!custInfoList.isEmpty()) {
                CustomerUserInfoVO vo = custInfoList.get(0);
                if (null != vo.getChannelId()) {
                    CustomerDistributorTypeAndChannelVO channelVO = distributorChannelService.getDistributerChannelLevelById(vo.getChannelId());
                    responseResult.setData(channelVO);
                }
            }
        } catch (Exception e) {
            logger.error("getCustomerUserInfoById查询用户信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * @param
     * @return
     * @author zhaoyanbiao
     * @date 2019年1月9日11:43:07
     * @Description 查询所有的分销商渠道类型列表
     */
    @Override
    public ResponseResult<List<CustomerDistributorChannelTypeVO>> findDistributerChannelTypeList(@RequestBody DistributorChannelTypeCondition condition) {
        ResponseResult<List<CustomerDistributorChannelTypeVO>> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorChannelService.findDistributerChannelTypeList(condition));
        } catch (Exception e) {
            logger.error("findDistributerChannelTypeList查询所有的分销商渠道类型列表失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 批量查询会员信息
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<List<CustomerUserInfoVO>> getCustomerUserInfoByIds(@RequestBody CustomerInfoCondition condition) {
        ResponseResult<List<CustomerUserInfoVO>> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(customerService.findCustomerUserStoreByIds(condition.getCustomerIds()));
        } catch (Exception e) {
            logger.error("getCustomerUserInfoByIds批量查询会员信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 当前用户查询统计自己下面的会员
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<CustomerTotalVO> getCustomerTotalById(@RequestBody CustomerTotalCondition condition) {
        ResponseResult<CustomerTotalVO> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(customerService.getCustomerTotalById(condition));
        } catch (Exception e) {
            logger.error("getCustomerTotalById当前用户查询统计自己下面的用户失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 查询当前用户收益与积分
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<CustomerRevenueVO> getCustomerRevenue(@RequestBody CustomerMyRevenueCondition condition) {
        ResponseResult<CustomerRevenueVO> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(customerRevenueService.getCustomerRevenue(condition.getCustomerId(), condition.getLevel()));
        } catch (Exception e) {
            logger.error("getCustomerRevenue当前用户查询统计收益与积分：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 分销商/会员基本信息 统计
     * @author: wangbaokuo
     * @date: 2019/1/11 11:14
     * @param: [id]
     * @return: com.winhxd.b2c.common.domain.ResponseResult<com.winhxd.b2c.common.domain.customer.vo.CustomerBaseCollectVO>
     */
    @Override
    public ResponseResult<List<CustomerBaseCollectVO>> findCustomerWallet(@RequestBody CustomerWalletCondition condition) {
        ResponseResult<List<CustomerBaseCollectVO>> result = new ResponseResult<>();
        try {
            logger.info("CustomerServiceController -> findCustomerWallet入参：" + JsonUtil.toJSONString(condition));
            if (null == condition || CollectionUtils.isEmpty(condition.getIds())) {
                result.setCode(BusinessCode.CODE_1007);
                return result;
            }
            result.setData(customerService.findCustomerWallet(condition));
        } catch (Exception e) {
            logger.error("CustomerServiceController -> findCustomerWallet查询失败：", e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    /**
     * 分销商/会员详情-收益日志
     * @author: wangbaokuo
     * @date: 2019/1/11 14:08
     * @param: [condition]
     * @return: com.winhxd.b2c.common.domain.ResponseResult<com.winhxd.b2c.common.domain.PagedList<com.winhxd.b2c.common.domain.customer.vo.CustomerRevenueDetailVO>>
     */
    @Override
    public ResponseResult<PagedList<CustomerRevenueDetailVO>> findUserRevenueDetail(@RequestBody CustomerRevenueDetailCondition condition) {
        ResponseResult<PagedList<CustomerRevenueDetailVO>> result = new ResponseResult<>();
        try {
            logger.info("CustomerServiceController -> findUserRevenueDetail入参：" + condition);
            if (null == condition || null == condition.getId()) {
                result.setCode(BusinessCode.CODE_1007);
                return result;
            }
            result.setData(customerService.getUserRevenueDetail(condition));
        } catch (Exception e) {
            logger.error("CustomerServiceController -> findUserRevenueDetail查询失败：", e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    /**
     * 分销商/会员详情-积分日志
     * @author: wangbaokuo
     * @date: 2019/1/11 14:08
     * @param: [condition]
     * @return: com.winhxd.b2c.common.domain.ResponseResult<com.winhxd.b2c.common.domain.PagedList<com.winhxd.b2c.common.domain.customer.vo.CustomerRevenueDetailVO>>
     */
    @Override
    public ResponseResult<PagedList<CustomerIntegralDetailVO>> findUserIntegralDetail(@RequestBody CustomerIntegralDetailCondition condition) {
        ResponseResult<PagedList<CustomerIntegralDetailVO>> result = new ResponseResult<>();
        try {
            logger.info("CustomerServiceController -> findUserIntegralDetail入参：" + condition);
            if (null == condition || null == condition.getId()) {
                result.setCode(BusinessCode.CODE_1007);
                return result;
            }
            result.setData(customerService.getUserIntegralDetail(condition));
        } catch (Exception e) {
            logger.error("CustomerServiceController -> findUserIntegralDetail查询失败：", e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    /**
     * 提现记录列表
     * @author: wangbaokuo
     * @date: 2019/1/12 10:02
     * @param: [condition]
     * @return: com.winhxd.b2c.common.domain.ResponseResult<com.winhxd.b2c.common.domain.PagedList<com.winhxd.b2c.common.domain.customer.vo.CustomerWithdrawalsVO>>
     */
    @Override
    public ResponseResult<PagedList<CustomerWithdrawalsVO>> findPayWithdrawals(@RequestBody CustomerWithdrawalsCondition condition) {
        ResponseResult<PagedList<CustomerWithdrawalsVO>> result = new ResponseResult<>();
        try {
            logger.info("CustomerServiceController -> findPayWithdrawals入参：" + condition);
            result.setData(customerService.findPayWithdrawals(condition));
        } catch (Exception e) {
            logger.error("CustomerServiceController -> findPayWithdrawals查询失败：", e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    /**
     * 提现审核
     * @author: wangbaokuo
     * @date: 2019/1/12 10:13
     * @param: [condition]
     * @return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.Integer>
     */
    @Override
    public ResponseResult<Integer> auditPayWithdrawals(@RequestBody CustomerAuditCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        try {
            if (null == condition || null == condition.getId()) {
                result.setCode(BusinessCode.CODE_1007);
                return result;
            }
            logger.info("CustomerServiceController -> auditPayWithdrawals入参：" + condition);
            result.setData(customerService.auditPayWithdrawals(condition));
        } catch (Exception e) {
            logger.error("CustomerServiceController -> auditPayWithdrawals查询失败：", e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<List<CustomerAddressVO>> selectCustomerAddressByUserId(@PathVariable("customerId") Long customerId) {
        logger.info("C端—查询当前用户所有收货地址, 参数：customerId={}", "", customerId);
        ResponseResult<List<CustomerAddressVO>> result = new ResponseResult<>();
        List<CustomerAddressVO> customerAddressList= customerAddressService.selectCustomerAddressByUserId(customerId);
        result.setData(customerAddressList);
        return result;
    }

    /**
     * 分销商/会员详情-收益日志
     * @author: zhaoyanbiao
     * @date: 2019/1/11 16:16
     * @param: [condition]
     * @return:
     */
    @Override
    public ResponseResult<PagedList<CustomerStoreVO>> findCustomerStoreList(@RequestBody  CustomerStoreInfoCondition condition) {
        ResponseResult<PagedList<CustomerStoreVO>> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(customerStoreInfoSerivce.findCustomerStoreList(condition));
        } catch (Exception e) {
            logger.error("saveStoreUserInfo：查询门店列表失败",e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 查询首页提现申请数
     *
     * @return 提现申请数
     */
    @Override
    public ResponseResult<Integer> getWithdrawDepositNum() {
        ResponseResult<Integer> responseResult = new ResponseResult<>();
        responseResult.setData(customerService.getWithdrawDepositNum());
        return responseResult;
    }

    /**
     * 修改门店信息
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyCustomerStoreInfo(@RequestBody  CustomerStoreInfoCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        responseResult.setData(customerStoreInfoSerivce.modifyCustomerStoreInfo(condition));
        return responseResult;
    }

    @Override
    public ResponseResult<CustomerUserInfo> getCustomerUserById(@PathVariable(value = "id") Long id) {
        ResponseResult<CustomerUserInfo> responseResult = new ResponseResult<>();
        responseResult.setData(customerStoreInfoSerivce.getCustomerUserById(id));
        return responseResult;
    }

    @Override
    public ResponseResult<CustomerAddressVO> selectDefaultCustomerAddress(@PathVariable("customerId") Long customerId) {
        logger.info("查询当前用户默认收货地址, 参数：customerId={}", "", customerId);
        ResponseResult<CustomerAddressVO> result = new ResponseResult<>();
        CustomerUser user = new CustomerUser();
        user.setCustomerId(customerId);
        CustomerAddressVO address = customerAddressService.selectDefaultCustomerAddress(user);
        result.setData(address);
        return result;
    }

    /**
     * @param condition
     * @return  CustomerStoreVO
     * @author wangzekun
     * @date 2019/1/15
     * @Description 根据渠道ID和等级查询分销商信息
     */
    @Override
    public ResponseResult<List<CustomerUserInfoVO>> findDistributorListByChannelIdAndLevel(CustomerDistributorCondition condition) {
        ResponseResult<List<CustomerUserInfoVO>> result = new ResponseResult<>();
        List<CustomerUserInfoVO> vo=distributorService.findDistributorListByChannelIdAndLevel(condition);
        result.setData(vo);
        return result;
    }

    /**
     * 后台保存分销商详情信息
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyDistributor(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<Boolean>();
        result.setData(distributorService.modifyDistributor(condition));
        return result;
    }



    /**
     * 会员换绑
     *
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<Boolean> modifyMemberDistributorBind(@RequestBody CustomerDistributorCondition condition) {
        ResponseResult<Boolean> responseResult = new ResponseResult<>();
        try {
            responseResult.setData(distributorService.modifyMemberDistributorBind(condition));
        } catch (Exception e) {
            logger.error("modifyMemberDistributorBind：会员换绑失败", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    @Override
    public ResponseResult<PagedList<ShopPlanVO>> findCustomerShopPlanList(ShopPlanCondition condition) {
        ResponseResult<PagedList<ShopPlanVO>> responseResult = new ResponseResult<PagedList<ShopPlanVO>>();
        try {
            PagedList<ShopPlanVO> page = customerStoreInfoSerivce.findCustomerShopPlanList(condition);
            responseResult.setData(page);
        } catch (Exception e) {
            logger.error("findCustomerShopPlanList查询开店方案信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }


    /**
     * 查询分销商下面的会员列表
     * @param condition
     * @return
     */
    @Override
    public ResponseResult<List<CustomerUserInfoVO>> findDistributorMemberList(DistributorQueryCondition condition) {
        ResponseResult<List<CustomerUserInfoVO>> responseResult = new ResponseResult<>();
        try {
            List<CustomerUserInfoVO> list = distributorService.findDistributorMemberList(condition);
            responseResult.setData(list);
        } catch (Exception e) {
            logger.error("findDistributorMemberList查询分销商下面的会员信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 查询当前用户上级信息
     * @param customerId
     * @return
     */
    @Override
    public ResponseResult<CustomerUserInfo> getParentCustomerUserByCustoemrId(@RequestParam(value = "customerId") Long customerId) {
        ResponseResult<CustomerUserInfo> responseResult = new ResponseResult<>();
        try {
            CustomerUserInfo customerUserInfo = customerStoreInfoSerivce.getParentCustomerUserByCustoemrId(customerId);
            responseResult.setData(customerUserInfo);
        } catch (Exception e) {
            logger.error("getParentCustomerUserByCustoemrId查询当前用户上级信息失败：", e);
            responseResult.setCode(BusinessCode.CODE_1001);
        }
        return responseResult;
    }

    /**
     * 校验添加一级分销商传入的参数
     */
    private void verfiySaveDistributerParams(CustomerDistributorCondition condition) {
        //校验手机号不能为空
        if (null == condition.getCustomerMobile()) {
            logger.info("输入的分销商手机号" + condition.getCustomerMobile() + "不能为空");
            throw new BusinessException(BusinessCode.CODE_200002);
        }
        //校验手机号格式
        if (!SecurityCheckUtil.validateMobile(condition.getCustomerMobile())) {
            logger.info("输入的分销商手机号" + condition.getCustomerMobile() + "格式不正确");
            throw new BusinessException(BusinessCode.CODE_200003);
        }
        //校验分销商渠道
        if (null == condition.getChannelId()) {
            logger.error("输入的分销商渠道不能为空", JsonUtil.toJSONString(condition));
            throw new BusinessException(BusinessCode.CODE_200004);
        }
        //校验隶属部门和员工
        if (null == condition.getFirstParentId()) {
            logger.error("分销商的隶属部门和员工不能为空", JsonUtil.toJSONString(condition));
            throw new BusinessException(BusinessCode.CODE_200005);
        }
    }
}

